﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BusinessObjects.BO_GetObjects;

public partial class Controls_HomeBlock : Base_Controls
{
    protected void Page_Load(object sender, EventArgs e)
    {
        base.setField(Convert.ToInt32(this.Attributes["ID"]));
        if (!IsPostBack)
        {
            loadData();
        }
    }
    protected void loadData()
    {
        int lang = 0;
        if (base.Lang)
            lang = 1;
        DataTable objDT = BO_portal_articles.SelectLangByModule(Convert.ToInt32(this.Attributes["ID"]), base.PSize, lang);
        //if (base.Lang)
        //{
        //    foreach (DataRow row in objDT.Rows)
        //    {
        //        row["FULL_ARTICLE_TITLE"] = row["FULL_ARTICLE_TITLE_ENG"];
        //        row["FULL_ARTICLE_DESCRIPTION"] = row["FULL_ARTICLE_DESCRIPTION_ENG"];
        //    }
        //}
        if (objDT.Rows.Count > 0)
        {
            imgFirstChild.Src = "/upload/" + objDT.Rows[0]["THUMB_IMG"].ToString();
            idArticleName.InnerText = DigiLib.StringUtils.Substring(objDT.Rows[0]["FULL_ARTICLE_TITLE"].ToString(), 0, 56);
            idCategoryName.HRef = "/c" + objDT.Rows[0]["CATEGORY_ID"].ToString() + "/" + DigiLib.StringUtils.RemoveUnicode(idCategoryName.InnerText, "-") + ".html";
            idCategoryReadmore.HRef = "/c" + objDT.Rows[0]["CATEGORY_ID"].ToString() + "/" + DigiLib.StringUtils.RemoveUnicode(idCategoryName.InnerText, "-") + ".html";
            idArticleName.HRef = "/tin-tuc/" + DigiLib.StringUtils.RemoveUnicode(objDT.Rows[0]["FULL_ARTICLE_TITLE"].ToString(), "-") + "-c" + objDT.Rows[0]["CATEGORY_ID"].ToString() + "a" + objDT.Rows[0]["ARTICLE_ID"].ToString() + ".htm";
            idArticleDescription.InnerText = DigiLib.StringUtils.Substring(objDT.Rows[0]["FULL_ARTICLE_DESCRIPTION"].ToString(), 0, 135);
            objDT.Rows.RemoveAt(0);
        }
        rptHome.DataSource = objDT;
        rptHome.DataBind();
        objDT = BO_portal_categories.Search(base.Cid);
        if (objDT.Rows.Count > 0)
        {
            if (Request["lang"] == "1")
            {
                idCategoryName.InnerText = objDT.Rows[0]["FULL_CATEGORY_NAME_ENG"].ToString();
            }
            else
                idCategoryName.InnerText = objDT.Rows[0]["FULL_CATEGORY_NAME"].ToString();
        }
    }
}